package com.sairobo.admin.modules.srblive.controller;

import com.sairobo.admin.modules.srblive.pojo.param.FileParam;
import com.sairobo.admin.modules.srblive.service.FileService;
import com.sairobo.base.common.entity.R;
import com.sairobo.base.common.utils.FileHelp;
import com.sairobo.base.modules.sys.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 文件目录
 *
 * @author admin
 * @email sairobo
 * @url www.sairobo.com
 * @date 2018年1月09日 上午10:41:05
 */
@RestController
@RequestMapping("/common/file")
public class FileController extends AbstractController {

    @Autowired
    FileService fileService;

    /**
     * 文件下载
     * @param response
     * @param request
     */
    @RequestMapping(method = RequestMethod.GET, value = "/download")
    public void downloadTemplate(String url,String fileName,HttpServletResponse response, HttpServletRequest request) {
        FileHelp.downloadResourceFile(url, fileName, request, response);
    }

    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public R springUpload(HttpServletRequest request, @RequestParam(value = "file")MultipartFile file, FileParam param)
            throws IllegalStateException, IOException, InstantiationException, IllegalAccessException {
        return fileService.multiUpload(request,file,param);
    }
}
